#!/bin/bash
# Author: afei
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

. /etc/os-release

#Different type of Linux System install Sudo
#sudo download: https://www.sudo.ws/

#Install rely
case "$ID" in
	rhel*|centos*)
	yum -y install wget gcc gcc-c++ dos2unix
	;;
	ubuntu*|kali*)
	apt-get install -y wget gcc dos2unix
	;;
esac

#Check root privilege
user=$(whoami)
Check_root()
	if [ $user == 'root' ];then
		printf "当前用户是root权限，正在进行升级，请稍后.../n"
		Install_Sudo
	else
		printf "\n请切换到root用户执行脚本！！！\n"
		su root
	fi

#Install Sudo
Install_Sudo(){
	#wget -P /opt/ https://www.sudo.ws/dist/sudo-1.9.5p2.tar.gz
	wget https://github.com/ltfafei/CVE-2021-3156/raw/master/sudo-1.9.5p2.tar.gz
	tar -xzf /opt/sudo-1.9.5p2.tar.gz -C /opt/ && cd /opt/sudo-1.9.5p2
	./configure && history -c && make -j 4 && make install -j 4
	#Clear shell Cache
	clear && /bin/bash -c 'echo 3 > /proc/sys/vm/drop_caches'
	echo "**********************************************"
	sleep 3
	printf "\n"
	/bin/bash -c "sudo -V |grep "Sudo" |sed -n '1p'"
	printf "\nYour Sudo upgrade success!\n"
	echo "**********************************************"
}

SUDO_Version=$(sudo -V |grep "Sudo" |sed -n '1p')
echo "当前sudo版本是:" $SUDO_Version
read -p "是否升级Sudo(y|n):" Confirm1
if [ $Confirm1 == 'y' -o $Confirm1 == 'Y' ];then
	Check_root
else
	printf "\n Your Sudo not upgrade!"
fi